package com.hdaccp.ch05

import org.apache.spark.SparkConf
import org.apache.spark.streaming.{Seconds, StreamingContext}

object Demo1 {
  def main(args: Array[String]): Unit = {
    //1.spark的配置
    val sparkConf = new SparkConf().setMaster("local[2]").setAppName("ch05Demo1App")
    //.2 Streaming的上下文
    val ssc = new StreamingContext(sparkConf,Seconds(5))
    //3.
    val lines = ssc.socketTextStream("192.168.15.11",12345)
    lines.flatMap(x=>x.split(" ")).map(y=>(y,1)).reduceByKey((a,b)=>a+b).print();

    ssc.start()
    ssc.awaitTermination()
  }
}
